
#import "Resource.h"

@implementation Resource

/// 读取Bundle中的图片资源
/// - Parameters:
///   - imageName: 图片名称
///   - bundleName: spec.resource_bundles时候设置的bundle名称
+ (UIImage *)imageNamed:(NSString *)imageName bundleName:(NSString *)bundleName {
    bundleName = [NSString stringWithFormat:@"/%@.bundle",bundleName];
    NSString *bundlePath = [[NSBundle bundleForClass:[self class]].resourcePath
                            stringByAppendingPathComponent:bundleName];
    NSBundle *resource_bundle = [NSBundle bundleWithPath:bundlePath];
    UIImage *image = [UIImage imageNamed:imageName
                                inBundle:resource_bundle
           compatibleWithTraitCollection:nil];
    return image;
}


+ (UIImage *)imageNamedInBundle:(NSString *)imageName {
    NSRange range = [NSStringFromClass(self.class) rangeOfString:@"Resource"];
    NSString *bundleName = [NSStringFromClass(self.class) substringToIndex:range.location];
    bundleName = [NSString stringWithFormat:@"/%@.bundle",bundleName];
    NSString *bundlePath = [[NSBundle bundleForClass:[self class]].resourcePath
                            stringByAppendingPathComponent:bundleName];
    NSBundle *resource_bundle = [NSBundle bundleWithPath:bundlePath];
    UIImage *image = [UIImage imageNamed:imageName
                                inBundle:resource_bundle
           compatibleWithTraitCollection:nil];
    return image;
}
@end
